﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace arcchallenge.filereader.tests
{
    [TestFixture]
    public class test_TextFileReader
    {
        [Test]
        public void Configure_with_a_path()
        {
            var config = new TextFileReader.Configuration();
            var sut = new TextFileReader(config);

            sut.In_Configure(@"c:\test\");

            Assert.AreEqual(@"c:\test\", config.defaultDirectoryname);
        }


        [Test]
        public void Normalize_default_path()
        {
            var config = new TextFileReader.Configuration();
            var sut = new TextFileReader(config);

            sut.In_Configure(@"c:\test");

            Assert.AreEqual(@"c:\test\", config.defaultDirectoryname);
        }


        [Test]
        public void Read_file()
        {
            var sut = new TextFileReader();
            var lines = new List<string>();

            sut.Out_Line += lines.Add;
            sut.In_ReadFile("3lines.txt");

            Assert.AreEqual(new[] {"1", "22", "333", null}, lines);
        }

        
        [Test]
        public void Read_file_from_default_dir()
        {
            var sut = new TextFileReader(new TextFileReader.Configuration{defaultDirectoryname = @"Testfiles\"});
            var lines = new List<string>();

            sut.Out_Line += lines.Add;
            sut.In_ReadFile("1Line.txt");

            Assert.AreEqual(new[] { "1", null }, lines);
        }
    }
}
